<?php
/**
 * 生成SOAP Web Service
 * 
 * @version $Id: Soap.php 135 2011-04-20 03:30:14Z linsir123 $
 */
class Soap
{
	/**
	 * @var WSDL路径
	 */
	private $wsdlUrl;
	
	/**
	 * @var 需要映射的类名称
	 */
	private $className;
	
	/**
	 * @var 服务名称
	 */
	private $serviceName;
	
	/**
	 * 构造函数
	 */
	public function __construct($wsdlUrl, $className, $serviceName)
	{
		$this->wsdlUrl = $wsdlUrl;
		$this->className = $className;
		$this->serviceName = $serviceName;
	}
	
	/**
	 * 处理服务请求
	 */
	public function handle()
	{
		ini_set('soap.wsdl_cache_enabled', '0');
		
		///
		if (isset($_SERVER['REQUEST_METHOD']) && strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') {
			$server = new SoapServer($this->wsdlUrl, array('encoding'=>'utf-8'));
			$server->setClass($this->className);
			$server->handle();
		} else {
			header("Content-type:text/xml");
			$wsdl = new Wsdl($this->wsdlUrl, $this->className, $this->serviceName);
			echo $wsdl->getWSDL();
		}
	}
}
